package com.amazon.SellingPartnerAPIAA;

import java.util.Arrays;
import java.util.HashSet;

/**
 * LWAAuthorizationCredentials
 */
public class LWAAuthorizationCredentials {
	/**
	 * LWA Client Id
	 */
	private String clientId;

	/**
	 * LWA Client Secret
	 */
	private String clientSecret;

	/**
	 * LWA Refresh Token
	 */
	private String refreshToken;

	/**
	 * LWA Authorization Server Endpoint
	 */
	private String endpoint;

	/**
	 * LWA Client Scopes
	 */
	private LWAClientScopes scopes;

//    public static class LWAAuthorizationCredentialsBuilder {
//
//        {
//            scopes = new LWAClientScopes(new HashSet<>());
//        }
//
//        public LWAAuthorizationCredentialsBuilder withScope(String scope) {
//            return withScopes(scope);
//        }
//
//        public LWAAuthorizationCredentialsBuilder withScopes(String... scopes) {
//            if (scopes != null) {
//                Arrays.stream(scopes).forEach(this.scopes::addScope);
//            }
//            return this;
//        }
//    }

	private LWAAuthorizationCredentials() {
	}

	private LWAAuthorizationCredentials(LWAAuthorizationCredentials origin) {
		this.endpoint = origin.endpoint;
		this.refreshToken = origin.refreshToken;
		this.clientId = origin.clientId;
		this.clientSecret = origin.clientSecret;
		this.scopes = origin.scopes;
	}

	public static LWAAuthorizationCredentials.Builder builder() {
		return new Builder();
	}

	public static class Builder {

		private LWAAuthorizationCredentials target;

		public Builder() {
			this.target = new LWAAuthorizationCredentials();
			this.target.scopes = new LWAClientScopes(new HashSet<>());
		}

		public Builder endpoint(String endpoint) {
			target.endpoint = endpoint;
			return this;
		}

		public Builder refreshToken(String refreshToken) {
			target.refreshToken = refreshToken;
			return this;
		}

		public Builder clientId(String clientId) {
			target.clientId = clientId;
			return this;
		}

		public Builder clientSecret(String clientSecret) {
			target.clientSecret = clientSecret;
			return this;
		}

		public Builder scopes(LWAClientScopes scopes) {
			target.scopes = scopes;
			return this;
		}

		public Builder withScope(String scope) {
			return withScopes(scope);
		}

		public Builder withScopes(String... scopes) {
			if (scopes != null) {
				Arrays.stream(scopes).forEach(this.target.scopes::addScope);
			}
			return this;
		}

		public LWAAuthorizationCredentials build() {
			return new LWAAuthorizationCredentials(target);
		}
	}

	public String getClientId() {
		return clientId;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public String getClientSecret() {
		return clientSecret;
	}

	public void setClientSecret(String clientSecret) {
		this.clientSecret = clientSecret;
	}

	public String getRefreshToken() {
		return refreshToken;
	}

	public void setRefreshToken(String refreshToken) {
		this.refreshToken = refreshToken;
	}

	public String getEndpoint() {
		return endpoint;
	}

	public void setEndpoint(String endpoint) {
		this.endpoint = endpoint;
	}

	public LWAClientScopes getScopes() {
		return scopes;
	}

	public void setScopes(LWAClientScopes scopes) {
		this.scopes = scopes;
	}

	@Override
	public String toString() {
		return "LWAAuthorizationCredentials [clientId=" + clientId + ", clientSecret=" + clientSecret
				+ ", refreshToken=" + refreshToken + ", endpoint=" + endpoint + ", scopes=" + scopes + "]";
	}

}
